#include "linkfabric/Registry.hpp"
#include <cstdint>

using namespace linkfabric;

void Registry::registerHost(const HostInfo& host) {
    hostTable_[host.hostname] = host;
}

std::vector<HostInfo> Registry::discover() {
    std::vector<HostInfo> out;
    for (auto& [_, h] : hostTable_) out.push_back(h);
    return out;
}

int Registry::assignChannel(const std::string& hostname) {
    auto it = hostTable_.find(hostname);
    if (it == hostTable_.end()) return -1;
    int cid = static_cast<int>(it->second.activeChannels.size());
    it->second.activeChannels.push_back(cid);
    return cid;
}

void Registry::reportAck(const std::string& hostname, int channelId, uint16_t seq) {
    // stub: record ack, can trigger retransmit logic
}